package com.sybil.ot.controlador;

import com.sybil.ot.servicio.SolicitudServicio;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class UsuarioControlador {

   @Autowired
   private SolicitudServicio solicitudServicio;

   @RequestMapping(value = "/login", method = RequestMethod.GET)
   public String formularioLogin(ModelMap model) {
      return "usuario/login";
   }

   @RequestMapping(value = "/index", method = RequestMethod.GET)
   public String bandeja(ModelMap model) {
      String usuarioActual = SecurityContextHolder.getContext().getAuthentication().getName();
      model.addAttribute("solicitudes", solicitudServicio.obtenerSolicitudes(usuarioActual));
      return "index";
   }
}
